/*
 * Copyright (C) 2010 TTPASI, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS-IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ttpasi.jgenere.chaocipher.testutils;

import static ttpasi.jgenere.chaocipher.testutils.AssertUtils.LINE_SEPARATOR;

import java.io.FileReader;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * @author Bruce [com.gmail @ ProgrammerBruce]
 */
public class FormatExhibitData
{
  public static String read(String fileName) throws Exception
  {
    Scanner scanner = new Scanner(new FileReader(fileName));
    StringBuilder text = new StringBuilder();
    while (scanner.hasNextLine())
    {
      String line = scanner.nextLine();
      text.append(line);
      if (scanner.hasNextLine())
      {
        text.append(LINE_SEPARATOR);
      }
    }
    scanner.close();
    return text.toString();
  }

  private static void format(String sourceFileName, String destFileName) throws Exception
  {
    FileReader in = new FileReader(sourceFileName);
    PrintWriter out = new PrintWriter(destFileName);
    for (int i = 1, nextChar = 0; (nextChar = in.read()) >= 0; i++)
    {
      char c = (char)nextChar;
      out.print(c);
      if (i % 5 == 0 && i > 1)
      {
        if (i % 55 == 0)
        {
          out.println();
        }
        else
        {
          out.print(" ");
        }
      }
    }
    out.close();
    in.close();
  }

  public static void main(String[] args) throws Exception
  {
    //format("test-data/chaocipher-exhibit-1.ct.txt", "test-data/formatted-chaocipher-exhibit-1.ct.txt");
    //format("test-data/chaocipher-exhibit-1.pt.txt", "test-data/formatted-chaocipher-exhibit-1.pt.txt");
    // then manually remove the ending space
  }
}
